<template>
  <div>
    <div style=" text-align: center;">
      <h1>项目管理</h1>
    </div>
    <!-- 项目列表 -->
    <div v-for="(item,index) in XiangMuList" :key="index">
      <el-descriptions title="项目信息" :column="1" class="custom-border">
        <el-descriptions-item label="项目名称">{{item.projectName}}</el-descriptions-item>
        <el-descriptions-item label="项目描述">{{item.projectDescribe}}</el-descriptions-item>
        <el-descriptions-item label="审核状态" v-if="item.status == 0"><el-tag size="small" type="warning">待审核</el-tag></el-descriptions-item>
        <el-descriptions-item label="审核状态" v-if="item.status == 1"><el-tag size="small" type="success">审核通过</el-tag></el-descriptions-item>
        <el-descriptions-item label="审核状态" v-if="item.status == 2"><el-tag size="small" type="danger">被驳回</el-tag></el-descriptions-item>
        <el-descriptions-item label="驳回原因" v-if="item.status == 2">{{ item.rejectReason }}</el-descriptions-item>

        <template slot="extra">
          <el-button type="primary" size="small" class="btn " @click="dialogForm(item.id)">查看</el-button>
          <el-button type="primary" size="small" class="btn " @click="showDeleteConfirm(item.id,item.projectName)">删除</el-button>
        </template>
      </el-descriptions>
    </div>
    <!-- 弹窗表单 -->
    <el-dialog title="项目详情" :visible.sync="dialogFormVisible">
      <el-form :model="XiangMuForm" ref="XiangMuForm" label-width="80px" :rules="rules">
        <el-form-item label="项目名称" prop="projectName">
          <el-input v-model="XiangMuForm.projectName" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="项目描述" prop="projectDescribe">
          <el-input type="textarea" v-model="XiangMuForm.projectDescribe" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="项目内容" prop="projectFile">
          <Editor :height="200" v-model="XiangMuForm.projectFile"></Editor>
        </el-form-item>
        <el-form-item label="项目状态">
          <el-radio-group v-model="XiangMuForm.status">
            <el-radio :label="'0'">进行中</el-radio>
            <el-radio :label="'1'">已完成</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="reviseForm(XiangMuForm)">确定修改</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import { QueryInformation, ProgictById, reviseInformation, deleteInformation } from '@/api/api'
export default {
  data() {
    return {
      // 表单弹窗开关
      dialogFormVisible: false,
      // 项目列表
      XiangMuList: [],
      // 项目表单
      XiangMuForm: {
        projectStatus: '0'
      },
      id: '',
      // 图片上传
      fileList: [],
      // 表单效验
      rules: {
        projectName: [{ required: true, message: '请输入项目名称', trigger: 'blur' }],
        projectDescribe: [{ required: true, message: '请输入项目描述', trigger: 'blur' }],
        projectFile: [{ required: true, message: '请输入项目内容', trigger: 'blur' }]
      }
    }
  },
  methods: {
    // 查看按钮
    dialogForm(id) {
      this.dialogFormVisible = true
      console.log(id)

      ProgictById(id).then(res => {
        this.XiangMuForm = res.data.data
        console.log('XiangMuForm', res)
      })
    },
    // 询问是否删除
    showDeleteConfirm(id, projectName) {
      this.$confirm(`此操作将永久删除《${projectName}》, 是否继续?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.delXiangMuList(id)
        })
        .catch(() => {
          this.$message({
            type: 'warning',
            message: '已取消删除'
          })
        })
    },
    // 删除按钮
    delXiangMuList(id) {
      console.log(id)
      deleteInformation(id)
        .then(res => {
          this.$message.success('删除成功')
          this.getList()
          console.log(res)
        })
        .catch(err => {
          console.log(err)
        })
    },
    // 项目列表
    getList() {
      QueryInformation().then(res => {
        this.XiangMuList = res.data.data
        console.log('this.XiangMuList', this.XiangMuList)
      })
    },
    // 表单修改
    reviseForm(XiangMuForm) {
      this.$refs.XiangMuForm.validate(valid => {
        //开启校验
        if (valid) {
          // 如果校验通过，请求接口，允许提交表单
          this.dialogFormVisible = false
          const XiangMuFormlist = {
            id: this.id,
            projectName: XiangMuForm.projectName,
            projectDescribe: XiangMuForm.projectDescribe,
            projectFile: XiangMuForm.projectFile,
            projectStatus: XiangMuForm.projectStatus
          }
          reviseInformation(XiangMuFormlist).then(result => {
            if (result.data.code == 200) {
              this.getList()
              this.$message({
                message: '修改成功',
                type: 'success'
              })
            } else {
              this.$message.error({
                message: '修改失败' + result.data.message,
                type: 'error'
              })
            }
          })
        } else {
          //校验不通过
          return false
        }
      })
    }
  },
  created() {
    this.getList()
  }
}
</script>

<style lang="less" scoped>
.pagination-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100px; /* 根据需要设置高度 */
}
.custom-border {
  border-bottom: 1px solid #000000; /* 边框颜色和宽度可以根据需要调整 */
  border-radius: 4px; /* 设置边框圆角 */
  margin-bottom: 10px;
}
// ::v-deep .el-descriptions__body {
//   height: 65px;
// }
::v-deep .el-descriptions__header {
  height: 25px;
}
:deep .el-descriptions__extra {
  position: relative;
  top: 75px;
  right: 10px;
}
:deep .el-descriptions__extra .btn {
  display: flex;
  // justify-content: center;
  // align-items: center;
  margin-left: auto;
  margin-top: 10px;
}
</style>